package cn.wolfcode.p2p.mgrsite.shiro;

import org.springframework.context.annotation.Configuration;

/**
 * shiro 配置类
 */
@Configuration
public class ShiroConfig {

    /*//shiro过滤器
    @Bean
    public ShiroFilterFactoryBean shiroFilter(DefaultWebSecurityManager securityManager){

        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        // 安全管理器
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        // 登录URL
        shiroFilterFactoryBean.setLoginUrl("/login.html");

        //配置访问权限
        Map<String, String> filterChainDefinitionMap=new HashMap<>();
        filterChainDefinitionMap.put("/css/**", "anon"); //表示可以匿名访问
        filterChainDefinitionMap.put("/images/**", "anon");
        filterChainDefinitionMap.put("/js/**","anon");
        filterChainDefinitionMap.put("/logout","logout");
        filterChainDefinitionMap.put("/**","authc");//表示需要认证才可以访问

        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);

        //自定义 authc
        Map<String, Filter> filters = new HashMap<>();
        filters.put("authc", authc());
        shiroFilterFactoryBean.setFilters(filters);
        return shiroFilterFactoryBean;
    }
    // 安全管理器
    @Bean
    public DefaultWebSecurityManager securityManager(DBRealm dbRealm){
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        // 数据源
        securityManager.setRealm(dbRealm);
        return securityManager;
    }


    @Bean
    public DBRealm dbRealm(){
        return new DBRealm();
    }

    // 自定义 ExtendsFormAuthenticationFilter

    public ExtendsFormAuthenticationFilter authc(){

        return new ExtendsFormAuthenticationFilter();
    }*/
}
